package jtech.util;

import java.awt.image.BufferedImage;
import java.util.Arrays;

public enum ColorPalleta {

	RED(new int[][] { { 164, 0, 0, 1 }, { 124, 0, 0, 1 }, { 92, 4, 0, 1 }, { 68, 4, 0, 1 } }),
	BROWN(new int[][] { { 81, 52, 0, 1 }, { 66, 43, 0, 1 }, { 50, 30, 0, 1 }, { 36, 26, 0, 1 } }),
	YELLOW(new int[][] { { 252, 252, 72, 1 }, { 228, 204, 40, 1 }, { 204, 160, 16, 1 }, { 180, 116, 0, 1 } }),
	ORANGE(new int[][] { { 240, 132, 20, 1 }, { 196, 88, 16, 1 }, { 152, 56, 16, 1 }, { 108, 32, 12, 1 } }),
	WHITE(new int[][] { { 224, 224, 244, 1 }, { 152, 152, 180, 1 }, { 84, 84, 128, 1 }, { 36, 40, 76, 1 } }),
	BLUE(new int[][] { { 0, 60, 192, 1 }, { 0, 36, 148, 1 }, { 0, 20, 108, 1 }, { 0, 4, 76, 1 } }),
	GREEN(new int[][] { { 44, 180, 148, 1 }, { 20, 132, 92, 1 }, { 4, 84, 44, 1 }, { 0, 40, 12, 1 } }),
	PURPLE(new int[][] { { 152, 72, 176, 1 }, { 116, 48, 132, 1 }, { 80, 16, 76, 1 }, { 44, 8, 44, 1 } }),
	BLACK(new int[][] { { 40, 40, 40, 1 }, { 28, 28, 44, 1 }, { 20, 20, 32, 1 }, { 12, 12, 20, 1 } });
	
	private int[][] colorSet;
	private ColorPalleta(int[][] colorSet) {
		this.colorSet = colorSet;
	} 
	
	public void convert(BufferedImage image, ColorPalleta palleta) {
		int[][] sourcePixels = palleta.colorSet;

		for (int i = 0; i < image.getWidth(); i++) {
			for (int j = 0; j < image.getHeight(); j++) {
				int[] pixel = new int[4];
				image.getRaster().getPixel(i, j, pixel);
				for (int h = 0; h < sourcePixels.length; h++) {
					if (Arrays.equals(pixel, sourcePixels[h])) {
						image.getRaster().setPixel(i, j, colorSet[h]);
					}
				}
			}
		}
	}
	
}
